/*
 * Mark Claypool
 *
 * WPI
 * copyright 2003
 */

/* 

get-key.c

What integer value does getch() return when I press <some key>? 
The answer can be obtained from this following simple program.

Call this program as "get-key.c" and compile it as:

   gcc -o get-key get-key.c -lncurses

Then, run "get-key" at the shell prompt, and type the key whose value
you want printed.  Note that using the keypad() function would allow
us to compare the return values of getch() directly with '#define'
constants from "curses.h" such as KEY_LEFT, etc.

*/

#include <stdio.h>
#include <ncurses/curses.h>
#include <stdlib.h>

int main() {
  int c;

  /* initialize the curses library */  
  initscr();

  /* enable keyboard mapping so any keyboard input will be accepted */ 
  keypad(stdscr, TRUE);

  /* tell curses not to do NL->CR/NL  on output */ 
  nonl();
  
  /* take input chars one at a time, no wait for \n */ 
  cbreak();

  /* don't echo input */ 
  noecho();

  /* loop until ctrl-c */
  while (1) {
    c = getch();
    printf("'%c' == '%d'\n\r", c, c);
    fflush(stdout); /* hack to get it toappear */
  }

  /* close things down */
  endwin();
}

